/*
               File: AfiPrsN
        Description: Afiliacion de Persona Natural
             Author: GeneXus C# Generator version 8_0_0-201
       Generated on: 21 de Setiembre de 2010 17:41:25.58
       Program type: Callable routine
          Main DBMS: sqlserver
*/
namespace GeneXus.Programs {
   using System;
   using System.Collections;
   using GeneXus.Utils;
   using GeneXus.Resources;
   using GeneXus.Application;
   using GeneXus.Metadata;
   using com.genexus;
   using com.genexus.ui;
   using com.genexus.uifactory;
   using GeneXus.Windows;
   using System.Data;
   using System.Data.SqlClient;
   using GeneXus.Data;
   using GeneXus.Data.FAT;
   using GeneXus.Http;
   using GeneXus.Procedure;
   using System.Threading;
   using GeneXus.XML;
   using GeneXus.Encryption;
   using GeneXus.Http.Client;
   public class pafiprsn_wrapper : GXJWin
   {
      public pafiprsn_wrapper( int hnd ,
                               ModelContext jContext ) : base(hnd, jContext)
      {
      }

   }

   public class pafiprsn : GXWinProcedure
   {
      public pafiprsn( int hnd ,
                       ModelContext jContext ) : base(hnd, jContext)
      {
         IsMain = true;
         context = new GxContext();
         context.DataStores.Add(new GxDataStore( new GxSqlServer(),"Default"));
         dsDefault = context.GetDataStore("Default") ;
      }

      public pafiprsn( )
      {
         context = new GxContext();
         context.DataStores.Add(new GxDataStore( new GxSqlServer(),"Default"));
         dsDefault = context.GetDataStore("Default") ;
         IsMain = true;
      }

      public pafiprsn( IGxContext context ) : base(-1, null)
      {
         this.context = context;
         IsMain = false;
         dsDefault = context.GetDataStore("Default") ;
      }

      public pafiprsn( IGxContext context ,
                       int hnd ,
                       ModelContext jContext ) : base(hnd, jContext)
      {
         this.context = context;
         IsMain = false;
         dsDefault = context.GetDataStore("Default") ;
      }

      public void execute( short aP0_Tipdoccod ,
                           String aP1_Prsnrodoc ,
                           String aP2_Prsprinom ,
                           String aP3_Prssegnom ,
                           String aP4_Prsapepat ,
                           String aP5_Prsapemat ,
                           DateTime aP6_Prsfecnac ,
                           String aP7_Prssex ,
                           short aP8_Estcivcod ,
                           short aP9_Prsnrodep ,
                           short aP10_Edunivcod ,
                           short aP11_Sitlabcod ,
                           String aP12_Prsucr ,
                           String aP13_Prsdir1 ,
                           String aP14_Prsdir2 ,
                           String aP15_Prsrefdir1 ,
                           String aP16_Prsrefdir2 ,
                           String aP17_Paicod1 ,
                           String aP18_Paicod2 ,
                           String aP19_Dptocod1 ,
                           String aP20_Dptocod2 ,
                           String aP21_Provcod1 ,
                           String aP22_Provcod2 ,
                           String aP23_Distcod1 ,
                           String aP24_Distcod2 ,
                           String aP25_Prsmai1 ,
                           String aP26_Prsmai2 ,
                           String aP27_Prsmai3 ,
                           out String aP28_Prscod )
      {
         this.AV10Tipdoc = aP0_Tipdoccod;
         this.AV11Prsnro = aP1_Prsnrodoc;
         this.AV12Prspri = aP2_Prsprinom;
         this.AV13Prsseg = aP3_Prssegnom;
         this.AV15Prsape = aP4_Prsapepat;
         this.AV14Prsape = aP5_Prsapemat;
         this.AV16Prsfec = aP6_Prsfecnac;
         this.AV17Prssex = aP7_Prssex;
         this.AV18Estciv = aP8_Estcivcod;
         this.AV19Prsnro = aP9_Prsnrodep;
         this.AV20Eduniv = aP10_Edunivcod;
         this.AV21Sitlab = aP11_Sitlabcod;
         this.AV23Prsucr = aP12_Prsucr;
         this.AV24Prsdir = aP13_Prsdir1;
         this.AV25Prsdir = aP14_Prsdir2;
         this.AV26Prsref = aP15_Prsrefdir1;
         this.AV27Prsref = aP16_Prsrefdir2;
         this.AV28Paicod = aP17_Paicod1;
         this.AV29Paicod = aP18_Paicod2;
         this.AV30Dptoco = aP19_Dptocod1;
         this.AV31Dptoco = aP20_Dptocod2;
         this.AV32Provco = aP21_Provcod1;
         this.AV33Provco = aP22_Provcod2;
         this.AV34Distco = aP23_Distcod1;
         this.AV35Distco = aP24_Distcod2;
         this.AV36Prsmai = aP25_Prsmai1;
         this.AV37Prsmai = aP26_Prsmai2;
         this.AV38Prsmai = aP27_Prsmai3;
         this.AV8Prscod = "" ;
         initialize();
         executePrivate();
         aP28_Prscod=this.AV8Prscod;
      }

      public void executeSubmit( short aP0_Tipdoccod ,
                                 String aP1_Prsnrodoc ,
                                 String aP2_Prsprinom ,
                                 String aP3_Prssegnom ,
                                 String aP4_Prsapepat ,
                                 String aP5_Prsapemat ,
                                 DateTime aP6_Prsfecnac ,
                                 String aP7_Prssex ,
                                 short aP8_Estcivcod ,
                                 short aP9_Prsnrodep ,
                                 short aP10_Edunivcod ,
                                 short aP11_Sitlabcod ,
                                 String aP12_Prsucr ,
                                 String aP13_Prsdir1 ,
                                 String aP14_Prsdir2 ,
                                 String aP15_Prsrefdir1 ,
                                 String aP16_Prsrefdir2 ,
                                 String aP17_Paicod1 ,
                                 String aP18_Paicod2 ,
                                 String aP19_Dptocod1 ,
                                 String aP20_Dptocod2 ,
                                 String aP21_Provcod1 ,
                                 String aP22_Provcod2 ,
                                 String aP23_Distcod1 ,
                                 String aP24_Distcod2 ,
                                 String aP25_Prsmai1 ,
                                 String aP26_Prsmai2 ,
                                 String aP27_Prsmai3 ,
                                 out String aP28_Prscod )
      {
         pafiprsn objpafiprsn;
         objpafiprsn = new pafiprsn();
         objpafiprsn.AV10Tipdoc = aP0_Tipdoccod;
         objpafiprsn.AV11Prsnro = aP1_Prsnrodoc;
         objpafiprsn.AV12Prspri = aP2_Prsprinom;
         objpafiprsn.AV13Prsseg = aP3_Prssegnom;
         objpafiprsn.AV15Prsape = aP4_Prsapepat;
         objpafiprsn.AV14Prsape = aP5_Prsapemat;
         objpafiprsn.AV16Prsfec = aP6_Prsfecnac;
         objpafiprsn.AV17Prssex = aP7_Prssex;
         objpafiprsn.AV18Estciv = aP8_Estcivcod;
         objpafiprsn.AV19Prsnro = aP9_Prsnrodep;
         objpafiprsn.AV20Eduniv = aP10_Edunivcod;
         objpafiprsn.AV21Sitlab = aP11_Sitlabcod;
         objpafiprsn.AV23Prsucr = aP12_Prsucr;
         objpafiprsn.AV24Prsdir = aP13_Prsdir1;
         objpafiprsn.AV25Prsdir = aP14_Prsdir2;
         objpafiprsn.AV26Prsref = aP15_Prsrefdir1;
         objpafiprsn.AV27Prsref = aP16_Prsrefdir2;
         objpafiprsn.AV28Paicod = aP17_Paicod1;
         objpafiprsn.AV29Paicod = aP18_Paicod2;
         objpafiprsn.AV30Dptoco = aP19_Dptocod1;
         objpafiprsn.AV31Dptoco = aP20_Dptocod2;
         objpafiprsn.AV32Provco = aP21_Provcod1;
         objpafiprsn.AV33Provco = aP22_Provcod2;
         objpafiprsn.AV34Distco = aP23_Distcod1;
         objpafiprsn.AV35Distco = aP24_Distcod2;
         objpafiprsn.AV36Prsmai = aP25_Prsmai1;
         objpafiprsn.AV37Prsmai = aP26_Prsmai2;
         objpafiprsn.AV38Prsmai = aP27_Prsmai3;
         objpafiprsn.AV8Prscod = "" ;
         objpafiprsn.initialize();
         Thread execThread;
         execThread = new Thread(new ThreadStart( objpafiprsn.executePrivate ));
         execThread.Start();
         aP28_Prscod=this.AV8Prscod;
      }

      void executePrivate( )
      {
         /* GeneXus formulas */
         /* Output device settings */
         AV39Cod = 1000000000L ;
         cmP00052 = new GxDbCommand(dsDefault.Db, "SELECT [PrsCod] FROM [MMPRS10] (NOLOCK) ORDER BY [PrsCod] DESC ", 0, dsDefault,"AfiPrsN","P00052" );
         cmP00052.DbCommand.FetchSize = 100;
         cmP00052.DbCommand.BindString(0,10);
         cmP00052.ErrorMask = GxErrorMask.Lock;
         cmP00052.FetchData( out P00052);
         while ( cmP00052.HasMoreRows )
         {
            A35PrsCod = dsDefault.Db.GetString(cmP00052, P00052, 0) ;
            AV39Cod = (long)(NumberUtil.Val( A35PrsCod)) ;
            /* Exit For each command. Update data (if necessary), close cursors & exit. */
            if (true) break;
            /* Check if program is canceled. */
            cmP00052.HasMoreRows = P00052.Read();
         }
         if ( ( cmP00052 != null ) )
         {
            cmP00052.DbCommand.Close();
         }
         dsDefault.Release() ;
         AV39Cod = (long)(AV39Cod+1) ;
         AV8Prscod = StringUtil.Str( AV39Cod, 10, 0) ;
         /*
            INSERT RECORD ON TABLE MMPRS10

         */
         A35PrsCod = AV8Prscod ;
         A52TipPrsC = 1 ;
         A53TIPDOCC = AV10Tipdoc ;
         A55PrsNroD = AV11Prsnro ;
         A57PrsPriN = AV12Prspri ;
         A58PrsSegN = AV13Prsseg ;
         A59PrsApeP = AV15Prsape ;
         A60PrsApeM = AV14Prsape ;
         A61PrsFecN = AV16Prsfec ;
         A63PrsSex = AV17Prssex ;
         A64EstCivC = AV18Estciv ;
         A65PrsNroD = AV19Prsnro ;
         A66EduNivC = AV20Eduniv ;
         A67SitLabC = AV21Sitlab ;
         A77PrsEst = "1" ;
         A80PrsUCR = AV23Prsucr ;
         A78PrsFCR = DateTimeUtil.ServerDate( context, "DEFAULT") ;
         A79PrsHCR = DateTimeUtil.ServerTime( context, "DEFAULT") ;
         A238PrsDir = AV24Prsdir ;
         A248PrsDir = AV25Prsdir ;
         A239PrsRef = AV26Prsref ;
         A249PrsRef = AV27Prsref ;
         A240PaiCod = AV28Paicod ;
         A244PAICOD = AV29Paicod ;
         A241DPTOCO = AV30Dptoco ;
         A245DPTOCO = AV31Dptoco ;
         A242PROVCO = AV32Provco ;
         A246PROVCO = AV33Provco ;
         A243DISTCO = AV34Distco ;
         A247DISTCO = AV35Distco ;
         A254PrsEma = AV36Prsmai ;
         A255PrsEma = AV37Prsmai ;
         A256PrsEma = AV38Prsmai ;
         cmP00053 = new GxDbCommand(dsDefault.Db, "INSERT INTO [MMPRS10] ([PrsCod], [TipPrsCod], [TIPDOCCOD], [PrsNroDoc], [PrsPriNom], [PrsSegNom], [PrsApePat], [PrsApeMat], [PrsFecNac], [PrsSex], [EstCivCod], [PrsNroDep], [EduNivCod], [SitLabCod], [PrsEst], [PrsFCR], [PrsHCR], [PrsUCR], [PrsDir1], [PrsRefDir1], [PaiCod1], [DPTOCOD1], [PROVCOD1], [DISTCOD1], [PrsDir2], [PrsRefDir2], [PAICOD2], [DPTOCOD2], [PROVCOD2], [DISTCOD2], [PrsEmai1], [PrsEmai2], [PrsEmai3], [PrsNroRUC], [PrsFlgTarC], [PrsFlgDErr], [PrsFUM], [PrsHUM], [PrsUUM], [CiiuCod], [PrsRazSoc], [PrsRazCom], [PrsNroTrb], [PrsPagWeb], [PrsFchAni], [PrsNac], [PrsTipEmp]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, convert(int, 0), ' ', ' ', convert( datetime, '17530101' ), ' ', ' ', convert(int, 0), ' ', ' ', convert(int, 0), ' ', convert( datetime, '17530101' ), ' ', ' ')", 1, dsDefault,"AfiPrsN","P00053" );
         cmP00053.AddParameter(1,3,10,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(2,2,2,0,ParameterDirection.Input);   // GX_SQL_NUMERIC  GX_CS_SHORT
         cmP00053.AddParameter(2,2,4,0,ParameterDirection.Input);   // GX_SQL_NUMERIC  GX_CS_SHORT
         cmP00053.AddParameter(1,3,15,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,15,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,15,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,20,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,20,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(11,5,10,0,ParameterDirection.Input);   // GX_SQL_TIMESTAMP  GX_CS_DATE
         cmP00053.AddParameter(1,3,1,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(2,2,2,0,ParameterDirection.Input);   // GX_SQL_NUMERIC  GX_CS_SHORT
         cmP00053.AddParameter(2,2,2,0,ParameterDirection.Input);   // GX_SQL_NUMERIC  GX_CS_SHORT
         cmP00053.AddParameter(2,2,3,0,ParameterDirection.Input);   // GX_SQL_NUMERIC  GX_CS_SHORT
         cmP00053.AddParameter(2,2,2,0,ParameterDirection.Input);   // GX_SQL_NUMERIC  GX_CS_SHORT
         cmP00053.AddParameter(1,3,1,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(11,5,10,0,ParameterDirection.Input);   // GX_SQL_TIMESTAMP  GX_CS_DATE
         cmP00053.AddParameter(1,3,8,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,10,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,200,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,200,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,200,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,200,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,3,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,100,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,100,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         cmP00053.AddParameter(1,3,100,0,ParameterDirection.Input);   // GX_SQL_CHAR  GX_CS_STRING
         /* Using cursor P00053 */
         cmP00053.SetParameter(0,A35PrsCod);
         cmP00053.SetParameter(1,A52TipPrsC);
         cmP00053.SetParameter(2,A53TIPDOCC);
         cmP00053.SetParameter(3,A55PrsNroD);
         cmP00053.SetParameter(4,A57PrsPriN);
         cmP00053.SetParameter(5,A58PrsSegN);
         cmP00053.SetParameter(6,A59PrsApeP);
         cmP00053.SetParameter(7,A60PrsApeM);
         cmP00053.SetParameter(8,dsDefault.Db.DbmsTToC(A61PrsFecN));
         cmP00053.SetParameter(9,A63PrsSex);
         cmP00053.SetParameter(10,A64EstCivC);
         cmP00053.SetParameter(11,A65PrsNroD);
         cmP00053.SetParameter(12,A66EduNivC);
         cmP00053.SetParameter(13,A67SitLabC);
         cmP00053.SetParameter(14,A77PrsEst);
         cmP00053.SetParameter(15,dsDefault.Db.DbmsTToC(A78PrsFCR));
         cmP00053.SetParameter(16,A79PrsHCR);
         cmP00053.SetParameter(17,A80PrsUCR);
         cmP00053.SetParameter(18,A238PrsDir);
         cmP00053.SetParameter(19,A239PrsRef);
         cmP00053.SetParameter(20,A240PaiCod);
         cmP00053.SetParameter(21,A241DPTOCO);
         cmP00053.SetParameter(22,A242PROVCO);
         cmP00053.SetParameter(23,A243DISTCO);
         cmP00053.SetParameter(24,A248PrsDir);
         cmP00053.SetParameter(25,A249PrsRef);
         cmP00053.SetParameter(26,A244PAICOD);
         cmP00053.SetParameter(27,A245DPTOCO);
         cmP00053.SetParameter(28,A246PROVCO);
         cmP00053.SetParameter(29,A247DISTCO);
         cmP00053.SetParameter(30,A254PrsEma);
         cmP00053.SetParameter(31,A255PrsEma);
         cmP00053.SetParameter(32,A256PrsEma);
         cmP00053.ExecuteStmt();
         if ( ( cmP00053 != null ) )
         {
            cmP00053.DbCommand.Close();
         }
         dsDefault.Release() ;
         if ( cmP00053.DupKey )
         {
            Gx_err = 1 ;
            Gx_emsg = (String)(GXResourceManager.GetMessage("noupdate")) ;
         }
         else
         {
            Gx_err = 0 ;
            Gx_emsg = "" ;
         }
         /* End Insert */
         this.cleanup();
      }

      public override int getOutputType( )
      {
         return GxReportUtils.OUTPUT_RVIEWER_DLL ;
      }

      protected void cleanup( )
      {
         this.AV8Prscod = AV8Prscod;
         dsDefault.Commit();
         if ( IsMain )
         {
            context.CloseConnections() ;
         }
      }

      public override void initialize( )
      {
         AV39Cod = 0 ;
         A35PrsCod = "" ;
         GX_INS2 = 0 ;
         A52TipPrsC = 0 ;
         A53TIPDOCC = 0 ;
         A55PrsNroD = "" ;
         A57PrsPriN = "" ;
         A58PrsSegN = "" ;
         A59PrsApeP = "" ;
         A60PrsApeM = "" ;
         A61PrsFecN = (DateTime)(DateTime.MinValue) ;
         A63PrsSex = "" ;
         A64EstCivC = 0 ;
         A65PrsNroD = 0 ;
         A66EduNivC = 0 ;
         A67SitLabC = 0 ;
         A77PrsEst = "" ;
         A80PrsUCR = "" ;
         A78PrsFCR = (DateTime)(DateTime.MinValue) ;
         A79PrsHCR = "" ;
         A238PrsDir = "" ;
         A248PrsDir = "" ;
         A239PrsRef = "" ;
         A249PrsRef = "" ;
         A240PaiCod = "" ;
         A244PAICOD = "" ;
         A241DPTOCO = "" ;
         A245DPTOCO = "" ;
         A242PROVCO = "" ;
         A246PROVCO = "" ;
         A243DISTCO = "" ;
         A247DISTCO = "" ;
         A254PrsEma = "" ;
         A255PrsEma = "" ;
         A256PrsEma = "" ;
         Gx_err = 0 ;
         Gx_emsg = "" ;
         /* GeneXus formulas. */
         Gx_err = 0 ;
      }

      private short AV10Tipdoc ;
      private short AV18Estciv ;
      private short AV19Prsnro ;
      private short AV20Eduniv ;
      private short AV21Sitlab ;
      private short A52TipPrsC ;
      private short A53TIPDOCC ;
      private short A64EstCivC ;
      private short A65PrsNroD ;
      private short A66EduNivC ;
      private short A67SitLabC ;
      private short Gx_err ;
      private int GX_INS2 ;
      private long AV39Cod ;
      private String AV11Prsnro ;
      private String AV12Prspri ;
      private String AV13Prsseg ;
      private String AV15Prsape ;
      private String AV14Prsape ;
      private String AV17Prssex ;
      private String AV23Prsucr ;
      private String AV24Prsdir ;
      private String AV25Prsdir ;
      private String AV26Prsref ;
      private String AV27Prsref ;
      private String AV28Paicod ;
      private String AV29Paicod ;
      private String AV30Dptoco ;
      private String AV31Dptoco ;
      private String AV32Provco ;
      private String AV33Provco ;
      private String AV34Distco ;
      private String AV35Distco ;
      private String AV36Prsmai ;
      private String AV37Prsmai ;
      private String AV38Prsmai ;
      private String A35PrsCod ;
      private String AV8Prscod ;
      private String A55PrsNroD ;
      private String A57PrsPriN ;
      private String A58PrsSegN ;
      private String A59PrsApeP ;
      private String A60PrsApeM ;
      private String A63PrsSex ;
      private String A77PrsEst ;
      private String A80PrsUCR ;
      private String A79PrsHCR ;
      private String A238PrsDir ;
      private String A248PrsDir ;
      private String A239PrsRef ;
      private String A249PrsRef ;
      private String A240PaiCod ;
      private String A244PAICOD ;
      private String A241DPTOCO ;
      private String A245DPTOCO ;
      private String A242PROVCO ;
      private String A246PROVCO ;
      private String A243DISTCO ;
      private String A247DISTCO ;
      private String A254PrsEma ;
      private String A255PrsEma ;
      private String A256PrsEma ;
      private String Gx_emsg ;
      private DateTime AV16Prsfec ;
      private DateTime A61PrsFecN ;
      private DateTime A78PrsFCR ;
      private IGxDataStore dsDefault ;
      private GxDbCommand cmP00052 ;
      private IDataReader P00052 ;
      private GxDbCommand cmP00053 ;
      private String aP28_Prscod ;
   }

}
